//
//  NewFeatureCollectionViewController.swift
//  weibo
//
//  Created by Mike on 15/5/14.
//  Copyright (c) 2015年 Mike. All rights reserved.
//

import UIKit

//let reuseIdentifier = "NewFeatureCell"

class NewFeatureCollectionViewController: UICollectionViewController {

    
    @IBOutlet weak var layout: UICollectionViewFlowLayout!
    
    let imageCount = 4 
    
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
//        println("\(__FUNCTION__), \(view.frame)")
        
        layout.itemSize = view.bounds.size
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        println("aaa")
    }
    /*
    // 调用了2次
    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()
        println("\(__FUNCTION__), \(view.frame)")
    }
    // 调用了2次
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        println("\(__FUNCTION__), \(view.frame)")
    }
*/
   

    // MARK: UICollectionViewDataSource
    override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return self.imageCount
    }

    override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        println("P")
        println(self.collectionView)
        let cell = self.collectionView?.dequeueReusableCellWithReuseIdentifier("NewFeatureCell", forIndexPath: indexPath) as! NewFeatureCell
        cell.imageIndex = indexPath.item
    
        return cell
    }


}


class NewFeatureCell: UICollectionViewCell {
    
    
    @IBOutlet weak var iconImageView: UIImageView!
    @IBOutlet weak var startButton: UIButton!
    
    var imageIndex: Int = 0 {
        didSet {
            self.iconImageView.image = UIImage(named: "new_feature_" + "\(imageIndex + 1)")
            self.startButton.hidden = true
        }
    }
}

